package com.againstsky.algorithm.sort;

import com.againstsky.algorithm.bean.SortBase;

/**
 * Created by agasinst on 2017/8/25.
 */
//插入排序最小对比次数N-1,最小交换次数0
public class Insertion extends SortBase {
    @Override
    public void sort(Comparable[] a) {
       int N=a.length;
        for (int i = 0; i < N; i++) {
            for(int j=i;j>0&&less(a[j],a[j-1]);j--){
                exch(a,j,j-1);
            }
        }
    }
}
